package com.yjhb.android.sbz.v2.mvp.presenter

import com.alibaba.fastjson.JSONObject
import com.yjhb.android.sbz.entity.Task
import com.yjhb.android.sbz.http.HttpObserver
import com.yjhb.android.sbz.http.HttpTool
import com.yjhb.android.sbz.mvp.ConventionPresenter2
import com.yjhb.android.sbz.v2.mvp.view.V2ReportView


/**
 *  创建者 zx
 *  创建时间 2021/4/8 16:31
 */
class V2ReportPresenter(v2ReportView: V2ReportView) : ConventionPresenter2<V2ReportView>(v2ReportView) {

    fun prosecutionDetail(id: Int) {
        view?.onLoading()
        model?.let {
            HttpTool.request(model.prosecutionDetail(id), object : HttpObserver<JSONObject?>() {
                override fun onResult(data: JSONObject?) {
                    data?.let {
                        view?.onLoadSuccess(it.getJSONArray("list").toJavaList(JSONObject::class.java))
                    }
                }

                override fun onError(code: Int, msg: String?) {
                    view?.onFailure(code, msg)
                }
            })
        }
    }

    fun queryTaskByOrderId(orderId:String){
        model?.let {
            HttpTool.request(model.queryTaskByOrderId(orderId),object : HttpObserver<Task?>() {
                override fun onResult(data: Task?) {
                    data?.let {
                        view?.onTaskDetail(it)
                    }
                }

                override fun onError(code: Int, msg: String?) {

                }
            })
        }
    }

}